﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using RCSoft.Core.Data;
using Autofac;
using RCSoft.Data;

namespace RCSoft.Hotal.UI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();
            var builder = new ContainerBuilder();
            builder.Register(c => dataSettingsManager.LoadSettings()).As<DataSettings>();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataProviderSettings);
                var dataProvider = (IEfDataProvider)efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register<IDbContext>(c => new RCSoftObjectContext(dataProviderSettings.DataConnectionString)).InstancePerDependency();
            }
            Application.Run(new Form1());
        }
    }
}
